﻿using System;
using System.Xml.Serialization;
using CTS.Com.Domain.Validate.Type;

namespace CTS.Com.Domain.Validate.Model
{
    [Serializable]
    public class Rule
    {
        [XmlAttribute(AttributeName = "name")]
        public string Name { get; set; }

        [XmlElement(ElementName = "Date")]
        public DateType DateType { get; set; }

        [XmlElement(ElementName = "Email")]
        public EmailType EmailType { get; set; }

        [XmlElement(ElementName = "Integer")]
        public IntegerType IntegerType { get; set; }

        [XmlElement(ElementName = "Real")]
        public RealType RealType { get; set; }

        [XmlElement(ElementName = "String")]
        public StringType StringType { get; set; }

        [XmlElement(ElementName = "Boolean")]
        public BooleanType BooleanType { get; set; }

        public override bool Equals(object obj)
        {
            if (obj == null) return false;
            if (GetType() != obj.GetType()) return false;
            var other = (Rule)obj;
            return (Name == null) ? (other.Name == null) : Name.Equals(other.Name);
        }

        public override int GetHashCode()
        {
            var hash = 5;
            hash = 59 * hash + (Name != null ? Name.GetHashCode() : 0);
            return hash;
        }
    }
}
